package com.zhuss.team.information;

import com.zhuss.bean.bo.team.information.DetailInfoBo;
import com.zhuss.bean.bo.team.information.SearchInfoBo;
import com.zhuss.bean.bo.team.information.wechat.DetailWeChatInfoBo;
import com.zhuss.bean.bo.team.information.wechat.SearchWeChatInfoBo;
import com.zhuss.common.ReadService;
import com.zhuss.enums.InfoType;
import com.zhuss.exception.WpsException;
import com.zhuss.team.processor.InformationRead;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

/**
 * @Author: zhushanshuo
 * @Date: 2020/3/3 14:25
 */
@Component("informationReadService")
public class InformationReadService implements ReadService<Object,Object> {

    @Autowired
    @Qualifier("informationRead")
    private InformationRead informationRead;

    @Override
    public Object detail(Object o) throws WpsException {
        DetailInfoBo bo = (DetailInfoBo) o;
        Object result = informationRead.detail(bo.getInfoId());
        return result;
    }

    @Override
    public Object list(Object o) throws WpsException {
        SearchInfoBo bo = (SearchInfoBo) o;
        Object result = informationRead.list(bo);
        return result;
    }

    /**
     * 获取微信通知公告列表
     * @throws WpsException
     */
    public Object noticeList(Object o) throws WpsException {
        SearchWeChatInfoBo bo = (SearchWeChatInfoBo) o;
        bo.setType(InfoType.通知公告.key().longValue());
        SearchInfoBo searchInfoBo = new SearchInfoBo();
        BeanUtils.copyProperties(bo,searchInfoBo);
        Object result = informationRead.list(searchInfoBo);
        return result;
    }

    /**
     * 获取微信新闻资讯列表
     * @throws WpsException
     */
    public Object newsList(Object o) throws WpsException {
        SearchWeChatInfoBo bo = (SearchWeChatInfoBo) o;
        bo.setType(InfoType.新闻资讯.key().longValue());
        SearchInfoBo searchInfoBo = new SearchInfoBo();
        BeanUtils.copyProperties(bo,searchInfoBo);
        Object result = informationRead.list(searchInfoBo);
        return result;
    }

    /**
     * 小程序段详情
     * @throws WpsException
     */
    public Object weChatDetail(Object o) throws WpsException {
        DetailWeChatInfoBo bo = (DetailWeChatInfoBo) o;
        Object result = informationRead.detail(bo.getInfoId());
        return result;
    }
}
